//
//  Extension.swift
//  GoCash
//
//  Created by jie on 2024/4/30.
//

import SwiftUI

extension Color {
    init(hex: Int, alpha: Double = 1.0) {
        let red = Double((hex >> 16) & 0xFF) / 255.0
        let green = Double((hex >> 8) & 0xFF) / 255.0
        let blue = Double(hex & 0xFF) / 255.0
        self.init(red: red, green: green, blue: blue, opacity: alpha)
    }
}




struct CustomCornerRadiusShape: Shape {
    var corners: Set<Int>
    var radius: CGFloat
 
    func path(in rect: CGRect) -> Path {
        var path = Path()
        for (index, corner) in corners.enumerated() {
            let cornerIndex = corner - 1
            if index == 0 {
                path.move(to: CGPoint(x: cornerIndex == 0 ? radius : rect.minX, y: cornerIndex == 1 ? radius : rect.minY))
            }
            path.addLine(to: CGPoint(x: cornerIndex == 0 ? radius : rect.maxX, y: cornerIndex == 1 ? radius : rect.maxY))
            path.addArc(center: CGPoint(x: cornerIndex == 0 ? radius : rect.maxX - radius, y: cornerIndex == 1 ? radius : rect.maxY - radius), radius: radius, startAngle: .degrees(Double(cornerIndex * 90)), endAngle: .degrees(Double((cornerIndex * 90) + 90)), clockwise: true)
            path.addLine(to: CGPoint(x: cornerIndex == 0 ? rect.maxX - radius : rect.maxX, y: cornerIndex == 1 ? rect.maxY - radius : rect.maxY))
        }
        return path
    }
}

